import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import useStore from '@/store/user'
import assembly from './modules/assembly'
// router/index.ts
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({
  easing: 'ease', // 动画方式
  speed: 500, // 递增进度条的速度
  showSpinner: false, // 是否显示加载 icon
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3, // 初始化时的最小百分比
})
// loading 配置
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'pagehome',
    meta: { title: '首页', icon: 'Briefcase', keepAlive: true },
    component: () => import('@/views/pagehome/index.vue'),
  },
  // 组件
  assembly,
  {
    path: '/cascader',
    name: 'cascader',
    meta: { title: '级联选择器', icon: 'IceCream' },
    component: () => import('@/views/cascader/index.vue'),
  },
  {
    path: '/directives',
    name: 'directives',
    meta: { title: '自定义指令', icon: 'Checked' },
    component: () => import('@/views/directive/index.vue'),
  },
  {
    path: '/iconSvg',
    name: 'iconSvg',
    meta: { title: 'Svg图标', icon: 'Histogram' },
    component: () => import('@/views/iconSvg/index.vue'),
  },
  {
    path: '/echarts',
    name: 'echarts',
    meta: { title: 'Echarts图线', icon: 'Coin' },
    component: () => import('@/views/echartsData/index.vue'),
  },
  {
    path: '/names',
    name: 'names',
    meta: { title: 'Echarts图线names', icon: 'Coin' },
    component: () => import('@/views/names/index.vue'),
  },
  {
    path: '/socket',
    name: 'socket',
    meta: { title: 'socket', icon: 'Coin' },
    component: () => import('@/views/socket/index.vue'),
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
})
router.beforeEach((to, from, next) => {
  NProgress.start() // 进度条开始
  useStore().GETROUTERDAT(to)
  next()
})

router.afterEach(() => {
  NProgress.done() // 进度条结束
})

export default router
